<?php 
/**
 * 附近门店导航小程序模块订阅器
 *
 * @author hellozjx
 * @url 
 */
defined('IN_IA') or exit('Access Denied');
class hellozjx_mapwxappModule extends WeModule
{
    public function settingsDisplay($settings)
    {
        global $_GPC, $_W;
        if (checksubmit()) {
            if (empty($_GPC['location']['lng']||$_GPC['location']['lat'])) {
                $lng = '';
				$lat = '';
            }
			else
			{
				$url = 'http://apis.map.qq.com/ws/coord/v1/translate?locations='.$_GPC['location']['lat'].','.$_GPC['location']['lng'].'&type=3&key=R2IBZ-3KOWO-OBWWY-SXICZ-4WOGH-WUFKO';
				$res = ihttp_get($url);
				$content = json_decode($res['content'], true);
				if ($content['status'] === 0) {
					$lng = $content['locations'][0]['lng'];
					$lat = $content['locations'][0]['lat'];
				} else {
					$lng = $_GPC['location']['lng'];
					$lat = $_GPC['location']['lat'];
				}
			}
			empty($_GPC['level'])?$level=16:$level=$_GPC['level'];
			empty($_GPC['distance'])?$distance=0:$distance=$_GPC['distance'];
            $cfg = array(
			'shop_lng' => $lng, 
			'shop_lat' => $lat, 
			'icon_type' => $_GPC['icon_type'], 
			'icon' => $_GPC['icon'], 
			'shop_lat_baidu'=>$_GPC['location']['lat'],
			'shop_lng_baidu'=>$_GPC['location']['lng'],
			'title' => $_GPC['title'], 
			'level' => $level, 
			'distance' => $distance, 
			);
            if ($this->saveSettings($cfg)) {
                message('配置成功', 'refresh','success');
            } else {
                message('配置信息有误', 'refresh', 'error');
            }
        }
        include $this->template('setting');
    }
}